#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置快捷键
    QShortcut* sub = new QShortcut(this);
    sub->setKey(QKeySequence("-"));
    QShortcut* add = new QShortcut(this);
    add->setKey(QKeySequence("+"));

    connect(sub,&QShortcut::activated,this,&Widget::subValue);
    connect(add,&QShortcut::activated,this,&Widget::addValue);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::subValue()
{
    //获取当前Slide的值
    int value = ui->horizontalSlider->value();
    //减少步长的值
    int step = ui->horizontalSlider->singleStep();
    ui->horizontalSlider->setValue(value-step);
}

void Widget::addValue()
{
    //获取当前Slide的值
    int value = ui->horizontalSlider->value();
    //减少步长的值
    int step = ui->horizontalSlider->singleStep();
    ui->horizontalSlider->setValue(value+step);
}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    //设置窗口大小 Geometry
    QRect rect = this->geometry();
    this->setGeometry(rect.x(),rect.y(),value,rect.height());
}

void Widget::on_verticalSlider_valueChanged(int value)
{
    //设置窗口大小 Geometry
    QRect rect = this->geometry();
    this->setGeometry(rect.x(),rect.y(),rect.width(),value);
}
